package com.zh.util;

import java.util.List;

/**
 * @author: JAVASM
 * @className:MyMail
 * @description:
 * @data:2021/4/28-23:07
 * @version:
 * @since: jdk 1.8
 */
public class MyMail {
    public static void mailLogin(String code,String email, List<String> tomails) throws Exception {
//        Properties properties = new Properties();
//        properties.setProperty("mail.host", "smtp.qq.com");
//        properties.setProperty("mail.transport.protocol", "smtp");
//        properties.setProperty("mail.smtp.auth", "true");
//        properties.put("mail.smtp.port", 465);
//
//        MailSSLSocketFactory sf = new MailSSLSocketFactory();
//        sf.setTrustAllHosts(true);
//        properties.put("mail.smtp.ssl.enable", "true");
//        properties.put("mail.smtp.ssl.socketFactory", sf);
//
//        Session instance = Session.getDefaultInstance(properties, new Authenticator() {
//            @Override
//            protected PasswordAuthentication getPasswordAuthentication() {
//                return new PasswordAuthentication("961995531@qq.com", "irwvuwfnnrhkbcee");
//            }
//        });
//        instance.setDebug(true);
//        Transport ts = instance.getTransport();
//        ts.connect("smtp.qq.com", "961995531@qq.com", "irwvuwfnnrhkbcee");
//        MimeMessage mimeMessage = new MimeMessage(instance);
//        mimeMessage.setFrom(new InternetAddress("961995531@qq.com"));
//        mimeMessage.setRecipients(Message.RecipientType.TO, mail);
//        mimeMessage.setSubject("验证码");
//        mimeMessage.setContent("<h1 style='color:red'>"+str+"</h1>", "text/html;charset=UTF-8");
//        ts.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
//        ts.close();

        MailSender mail = new MailSender();
        mail.setHost("smtp.qq.com");			// 设置 SMTP 主机
        mail.setFrom("961995531@qq.com");			// 设置发送者地址xxx@163.com
        mail.addTo("961995531@qq.com");// 添加发送目标地址xxx@xx.com
        mail.addTo(email); // 添加发送目标地址xxx@xx.com
        for (String tomail : tomails) {
            mail.addCc(tomail);

        }
//        mail.addCc("抄送的邮箱地址");				// 添加抄送目标地址xxx@xx.com
//        mail.addFileAcc("F:\\gitcode\\project3\\src\\main\\webapp\\WEB-INF\\img\\tianyi.jpg");			// 添加文件附件
        // 从 byte[] 中读取数据并添加为附件（这个功能有时非常有用）
//        mail.addByteAcc("我是大怪兽".getBytes(), MailSender.DEFAULT_CONTENT_TYPE, "我是谁.txt");
        mail.setAuth(true);						// 设置验证模式
        //mail.setNeedReceipt(true);				// 设置是否需要回执
        mail.setUser("961995531@qq.com");			// 设置邮箱登录名
        mail.setPassword("irwvuwfnnrhkbcee");			// 设置邮箱登录密码
        mail.setSubject("您有新的提醒");				// 设置邮件主题
        mail.setText("<h1 style='color:red'>"+code+"</h1>");// 设置邮件文本内容
        mail.setCharset("UTF-8");				// 设置邮件文本内容编码
        mail.setContentType("text/html;charset=UTF-8");		// 设置邮件文本内容格式
        mail.send();
    }
}
